package gui;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import util.Util;
import entity.Word;

/**
 * Table that stores the type and value of words. 
 */
public class BoardTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 8634095873188733988L;
	
	private String[] columnNames = {"Type", "Word"};
	
	private ArrayList<Word> words;
	
	public BoardTableModel(){
		words = new ArrayList<Word>();
	}

	public String getColumnName(int i) {
		return columnNames[i];
	}

	public int getColumnCount() {
		return 2;
	}

	public int getRowCount() {
		return words.size();
	}

	/**
	 * Get the value in a specific position in the table. 
	 */
	public Object getValueAt(int row, int column) {
		Word word = words.get(row);
		
		if(column == 0){
			return Util.wordTypeString(word.getWordType());
		}else if(column == 1){
			return word.getValue();
		}
		
		return null;
	}
	
	/**
	 * Update words. 
	 * @param words
	 */
	public void updateWords(ArrayList<Word> words){
		this.words = words;
		fireTableDataChanged();
	}
}
